<?php
/**
 * Description of class
 *
 * @author Henson
 */
class Base {
	
	public $db;
	
	public $pageRow = 20;
	
	public function __construct()
	{
		$this->db = new Mysql;
	}
	
	public function getTotalNum($tableName, $where='')
	{
		$sql = "select count(*) as total from `{$tableName}` {$where}";
		$count = $this->db->loadResult($sql);
		return $count;
	}
	
	public function checkPermission()
	{
		global $_CFG;
		$action_module = $_CFG['ROUTE']['ACTION'].'|'.$_CFG['ROUTE']['MODULE'];
		if(_checkSuperLogin())
		{
			$superId = $_COOKIE['r_uid'];
			if($superId == 1000)
			{
				return true;
			}
			else
			{
				$sql = "select permission from tbl_supervisor where id=".$superId;
				$permission = $this->db->loadResult($sql);
				$permissionArr = explode(',', $permission);
				foreach ($permissionArr as $permissionKey)
				{
					if(in_array($action_module, $_CFG['permission'][$permissionKey]))
					{
						return true;
					}
				}
				echo "您无权访问该功能，请联系系统管理员！";die;
			}
		}
	}
}
?>
